package metaClass;

import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import javassist.Translator;
import javassist.tools.reflect.Loader;


/**
 * @author 3153319 & 3003064
 *
 */
public class MyMetaTranslator implements Translator{

	Loader lo;
	
	public MyMetaTranslator(Loader l){
		this.lo=l;
	}
	
	/* (non-Javadoc)
	 * @see javassist.Translator#onLoad(javassist.ClassPool, java.lang.String)
	 */
	@Override
	public void onLoad(ClassPool pool, String classname) throws NotFoundException,
			CannotCompileException {
		if(classname.contains("metaClass")||
			classname.contains("stores")||
				classname.contains("junit")|| 
				classname.contains("annotation")|| 
				classname.contains("javassist.tools.reflect")|| 
				classname.startsWith("org.")|| 
				classname.endsWith(".class") || classname.startsWith("sun.reflect")){
			return;
		}
		CtClass myCtClass = pool.get(classname);
		while(myCtClass.getSuperclass() != null && !myCtClass.getSuperclass().getName().contains("java.lang.Object")){
			myCtClass = myCtClass.getSuperclass();
			System.out.println(myCtClass.getName());
			lo.makeReflective(myCtClass.getName(), "metaClass.VerboseMetaobj", "javassist.tools.reflect.ClassMetaobject");
		}
		System.out.println(classname);
		lo.makeReflective(classname, "metaClass.VerboseMetaobj", "javassist.tools.reflect.ClassMetaobject");
	
	}

	@Override
	public void start(ClassPool arg0) throws NotFoundException,
			CannotCompileException {		
	}

}
